package com.gengral.commons.utils;


import com.gengral.commons.constant.Constant;
import com.gengral.commons.msg.BaseResponse;

/**
 * http请求返回的最外层对象处理工具类
 *
 * @author
 * @version Created in 15:06 2020/1/19
 */
public class ResponseMsgUtil {

    /**
     * 处理成功响应方法-有结果集
     *
     * @param object 结果集对象
     * @return BaseResponse 包装后的统一结果实体
     */
    public static BaseResponse success(Object object) {
        BaseResponse baseResponse = new BaseResponse();
        baseResponse.setCode(Constant.SYS_CODE_SUCCESS);
        baseResponse.setMsg(Constant.SYS_MSG_SUCCESS);
        baseResponse.setData(object);
        return baseResponse;
    }

    /**
     * 处理成功响应方法-无结果集
     *
     * @return
     */
    public static BaseResponse success() {
        return success(null);
    }

    /**
     * 处理失败响应方法
     *
     * @param msg 错误信息
     * @return BaseResponse 包装后的统一结果实体
     */
    public static BaseResponse error(String msg) {
        BaseResponse baseResponse = new BaseResponse();
        baseResponse.setCode(Constant.SYS_CODE_ERROR);
        baseResponse.setMsg(msg);
        return baseResponse;
    }

    /**
     * 处理警告响应方法
     *
     * @param code
     * @param msg 错误信息
     * @return BaseResponse 包装后的统一结果实体
     */
    public static BaseResponse warn(int code, String msg) {
        BaseResponse baseResponse = new BaseResponse();
        baseResponse.setCode(code);
        baseResponse.setMsg(msg);
        return baseResponse;
    }

    /**
     * 处理失败响应方法
     *
     * @param msg 错误信息
     * @return BaseResponse 包装后的统一结果实体
     */
    public static BaseResponse error(Integer code, String msg) {
        BaseResponse baseResponse = new BaseResponse();
        baseResponse.setCode(code);
        baseResponse.setMsg(msg);
        return baseResponse;
    }
}
